---
title: "PEW"
author: "Jeppe Sabroe Thegen"
date: '2022-06-15'
output: html_document
---

```{r packages}
#Load packages
library(tidyverse)
library(haven)
library(labelled)

```

```{r inport}
PEW <- read_sav("ATP W82.sav")
#24-25 are the relevant ones
summary(PEW$GAP21Q24_W82)

```

```{r recode}
PEW$GAP21Q24_W82[PEW$GAP21Q24_W82 == 99] <- NA
PEW$concern <- range01(PEW$GAP21Q24_W82, na.rm = T)
PEW$concern <- PEW$concern*(-1)+1

PEW$F_GENDER[PEW$F_GENDER == 99] <- NA
PEW$male <- PEW$F_GENDER
PEW$male[PEW$male != 1] <- 0

```


```{r gender}
PEW$male <- PEW$male %>% to_factor()

Gmale <- PEW %>%
  group_by(male) %>%
  summarize(AvgConcern = mean(concern, na.rm = T),
            SDConcern = sd(concern, na.rm = T))

male_tally <- PEW %>% count(male)
MaleTally <- male_tally$n
Gmale<- cbind(Gmale,MaleTally)

#Laver nogle intervaller
Gmale$low <- Gmale$AvgConcern - (1.96 * (Gmale$SDConcern/(sqrt(Gmale$MaleTally))))
Gmale$high <- Gmale$AvgConcern + (1.96 * (Gmale$SDConcern/(sqrt(Gmale$MaleTally))))

ggmaleMTurk <- ggplot(Gmale[Gmale$male %in% c("0", "A man"),], aes(x = AvgConcern, y = male)) + geom_point() +
geom_errorbar(aes(xmin=low, xmax = high), alpha=0.5, linetype = 3) +
  coord_cartesian(xlim = c(0, 1), ylim=c(1,2), clip = "off") +
  labs(x = "", y = "", color = "", title = "Hvor bekymret er du for, at klimaforandringerne\nvil ramme dig i løbet af din livstid?", caption = "Kilde: PEW Research Center") +
  theme_minimal() +
  theme(legend.position = "top") + 
  geom_vline(xintercept = mean(PEW$concern, na.rm = T), linetype="dashed") +
  annotate(geom = "text", x = mean(PEW$concern, na.rm =T)-0.02, y = .8, label = "Gennemsnit", angle = 90, size = 3) + 
 # theme(plot.margin = unit(c(1, 1, 3, 1), "lines")) +
  annotate(geom = "text", x = c(0, 1), y = -Inf, label = c("Slet ikke bekymret", "Meget bekymret"), size = 2, color = "Dark Grey") + guides(fill = "none") +
  scale_y_discrete(labels=c("0" = "Ikke mand", "A man" = "Mand", limits=c("0", "1"), breaks = NULL, drop = F)) + theme(panel.grid.minor.y=element_blank(),
           panel.grid.major.y=element_blank())


tikz(file = "theorymale.tex",
     standAlone=F,
     width = 9,
     height = 3,
     sanitize =T,
     )

print(plot_grid(ggmaleDR, gggenderANES, 
          ncol =2))

dev.off()

```

```{r party}

PEW$F_PARTY_FINAL[PEW$F_PARTY_FINAL == 99] <- NA
PEW$F_PARTY_FINAL[PEW$F_PARTY_FINAL == 4] <- NA

PEW$party <- PEW$F_PARTY_FINAL %>% to_factor()

GParty <- PEW %>%
  group_by(party) %>%
  summarize(AvgConcern = mean(concern, na.rm = T),
            SDConcern = sd(concern, na.rm = T))

party_tally <- PEW %>% count(party)
PartyTally <- party_tally$n
GParty<- cbind(GParty,PartyTally)

#Laver nogle intervaller
GParty$low <- GParty$AvgConcern - (1.96 * (GParty$SDConcern/(sqrt(GParty$PartyTally))))
GParty$high <- GParty$AvgConcern + (1.96 * (GParty$SDConcern/(sqrt(GParty$PartyTally))))

ggpartyMTurk <- ggplot(GParty[GParty$party %in% c("Democrat", "Republican"),], aes(x = AvgConcern, y = party)) + geom_point() +
geom_errorbar(aes(xmin=low, xmax = high), alpha=0.5, linetype = 3) +
  coord_cartesian(xlim = c(0, 1), ylim=c(1,2), clip = "off") +
  labs(x = "", y = "", color = "", title = "Hvor bekymret er du for at klimaforandringerne\nvil ramme dig i din levetid?", caption = "Kilde: PEW Research Center") +
  theme_minimal() +
  theme(legend.position = "top") + 
  geom_vline(xintercept = mean(PEW$concern, na.rm = T), linetype="dashed") +
  annotate(geom = "text", x = mean(PEW$concern, na.rm =T)-0.02, y = .8, label = "Gennemsnit", angle = 90, size = 3) + 
 # theme(plot.margin = unit(c(1, 1, 3, 1), "lines")) +
  annotate(geom = "text", x = c(0, 1), y = -Inf, label = c("Slet ikke bekymret", "Meget bekymret"), size = 2, color = "Dark Grey") + guides(fill = "none") +
  scale_y_discrete(labels=c("Republican" = "Republikanere", "Democrat" = "Demokrater", "Independent" = "Uafhængige", limits=c("1", "2", "3"), breaks = NULL, drop = F)) + theme(panel.grid.minor.y=element_blank(),
           panel.grid.major.y=element_blank())

tikz(file = "theoryparty.tex",
     standAlone=F,
     width = 9,
     height = 3,
     sanitize =T,
     )

print(plot_grid(ggpartyMTurk, ggpartyANES, 
          ncol =2))

dev.off()

tikz(file = "theorypartyMTurk.tex",
     standAlone=F,
     width = 7,
     height = 4,
     sanitize =T,
     )

print(ggpartyMTurk)

dev.off()

```

```{r anes}

anes_timeseries_2020_stata_20220210 <- read_dta("anes_timeseries_2020_stata_20220210.dta")
forGG_ANES <- anes_timeseries_2020_stata_20220210 %>%
    mutate_if(
        haven::is.labelled,
        funs(haven::as_factor(.))
    )

forGG_ANES$V201510[forGG_ANES$V201510 == "-9. Refused"] <- NA
forGG_ANES$V201510[forGG_ANES$V201510 == "95. Other {SPECIFY}"] <- NA
forGG_ANES$V201510[forGG_ANES$V201510 == "-8. Don't know"] <- NA

forGG_ANES$party <- anes_timeseries_2020_stata_20220210$V201075x %>% as.character()

forGG_ANES$party[forGG_ANES$party == -1] <- NA

forGG_ANES$party[forGG_ANES$party == 10] <- "Democrat"
forGG_ANES$party[forGG_ANES$party == 20] <- "Democrat"
forGG_ANES$party[forGG_ANES$party == 30] <- "Democrat"

forGG_ANES$party[forGG_ANES$party == 11] <- "Republican"
forGG_ANES$party[forGG_ANES$party == 21] <- "Republican"
forGG_ANES$party[forGG_ANES$party == 31] <- "Republican"

forGG_ANES$party[forGG_ANES$party == 12] <- "Others"
forGG_ANES$party[forGG_ANES$party == 22] <- "Others"
forGG_ANES$party[forGG_ANES$party == 32] <- "Others"

forGG_ANES$party <- forGG_ANES$party %>% as.factor

#age
forGG_ANES$age <- forGG_ANES$V201507x
forGG_ANES$age[forGG_ANES$age == -9] <- NA

#Gender
forGG_ANES$gender <- forGG_ANES$V201600
forGG_ANES$gender[forGG_ANES$gender == "-9. Refused"] <- NA

#Concern
forGG_ANES$concern <- anes_timeseries_2020_stata_20220210$V202333
forGG_ANES$concern[forGG_ANES$concern == -9] <- NA
forGG_ANES$concern[forGG_ANES$concern == -7] <- NA
forGG_ANES$concern[forGG_ANES$concern == -6] <- NA
forGG_ANES$concern[forGG_ANES$concern == -5] <- NA

forGG_ANES$concern <- range01(forGG_ANES$concern, na.rm = T)

```

```{r ANES_party}

GParty <- forGG_ANES %>%
  group_by(party) %>%
  summarize(AvgConcern = mean(concern, na.rm = T),
            SDConcern = sd(concern, na.rm = T))

party_tally <- forGG_ANES %>% count(party)
PartyTally <- party_tally$n
GParty<- cbind(GParty,PartyTally)

#Laver nogle intervaller
GParty$low <- GParty$AvgConcern - (1.96 * (GParty$SDConcern/(sqrt(GParty$PartyTally))))
GParty$high <- GParty$AvgConcern + (1.96 * (GParty$SDConcern/(sqrt(GParty$PartyTally))))

ggpartyANES <- ggplot(GParty[GParty$party %in% c("Democrat", "Republican"),], aes(x = AvgConcern, y = fct_rev(as_factor(party)))) + geom_point() +
geom_errorbar(aes(xmin=low, xmax = high), alpha=0.5, linetype = 3) +
  coord_cartesian(xlim = c(0, 1), ylim=c(1,2), clip = "off") +
  labs(x = "", y = "", color = "", title = "Hvor vigtigt er emnet klimaforandringer\nfor dig personligt?", caption = "Kilde: American National Election Studies, 2020") +
  theme_minimal() +
  theme(legend.position = "top") + 
  geom_vline(xintercept = mean(forGG_ANES$concern, na.rm = T), linetype="dashed") +
  annotate(geom = "text", x = mean(forGG_ANES$concern, na.rm =T)-0.02, y = .8, label = "Gennemsnit", angle = 90, size = 3) + 
 # theme(plot.margin = unit(c(1, 1, 3, 1), "lines")) +
  annotate(geom = "text", x = c(0, 1), y = -Inf, label = c("Ikke vigtigt", "Meget vigtigt"), size = 2, color = "Dark Grey") + guides(fill = "none") +
  scale_y_discrete(labels=c("Democrat" = "Demokrater", "Others" = "Andre", "Republican" = "Republikanere", limits=c("1", "2", "3"), breaks = NULL, drop = F)) + theme(panel.grid.minor.y=element_blank(),
           panel.grid.major.y=element_blank())

```

```{r ANES gender}

Ggender <- forGG_ANES %>%
  group_by(gender) %>%
  summarize(AvgConcern = mean(concern, na.rm = T),
            SDConcern = sd(concern, na.rm = T))

gender_tally <- forGG_ANES %>% count(gender)
GenderTally <- gender_tally$n
GGender<- cbind(Ggender,GenderTally)

#Laver nogle intervaller
GGender$low <- GGender$AvgConcern - (1.96 * (GGender$SDConcern/(sqrt(GGender$GenderTally))))
GGender$high <- GGender$AvgConcern + (1.96 * (GGender$SDConcern/(sqrt(GGender$GenderTally))))

gggenderANES<- ggplot(GGender[GGender$gender %in% c("1. Male", "2. Female"),], aes(x = AvgConcern, y = fct_rev(as_factor(gender)))) + geom_point() +
geom_errorbar(aes(xmin=low, xmax = high), alpha=0.5, linetype = 3) +
  coord_cartesian(xlim = c(0, 1), ylim=c(1,2), clip = "off") +
  labs(x = "", y = "", color = "", title = "Hvor vigtigt er emnet klimaforandringer for dig?", caption = "Kilde: American National Election Studies, 2020") +
  theme_minimal() +
  theme(legend.position = "top") + 
  geom_vline(xintercept = mean(PEW$concern, na.rm = T), linetype="dashed") +
  annotate(geom = "text", x = mean(PEW$concern, na.rm =T)-0.02, y = .8, label = " Gennemsnit", angle = 90, size = 3) + 
 # theme(plot.margin = unit(c(1, 1, 3, 1), "lines")) +
  annotate(geom = "text", x = c(0, 1), y = -Inf, label = c("Ikke vigtigt", "Meget vigtigt"), size = 2, color = "Dark Grey") + guides(fill = "none") +
  scale_y_discrete(labels=c("1. Male" = "Mænd", "2. Female" = "Kvinder", "Uafhængig", limits=c("1", "2", "3"), breaks = NULL, drop = F)) + theme(panel.grid.minor.y=element_blank(),
           panel.grid.major.y=element_blank())

```

```{r ANES education}

forGG_ANES$V201510[forGG_ANES$V201510 == "-9. Refused"] <- NA
forGG_ANES$V201510[forGG_ANES$V201510 == "95. Other {SPECIFY}"] <- NA
forGG_ANES$V201510[forGG_ANES$V201510 == "-8. Don't know"] <- NA

Gedu <- forGG_ANES %>%
  group_by(V201510) %>%
  summarize(AvgConcern = mean(concern, na.rm = T),
            SDConcern = sd(concern, na.rm = T))

edu_tally <- forGG_ANES %>% count(V201510)
EduTally <- edu_tally$n
GGedu <- cbind(Gedu,EduTally)

#Laver nogle intervaller
GGedu$low <- GGedu$AvgConcern - (1.96 * (GGedu$SDConcern/(sqrt(GGedu$EduTally))))
GGedu$high <- GGedu$AvgConcern + (1.96 * (GGedu$SDConcern/(sqrt(GGedu$EduTally))))

ggeduUSA <- ggplot(GGedu[-c(9), ], aes(x = AvgConcern, y = V201510)) + geom_point()+
geom_errorbar(aes(xmin=low, xmax = high), alpha=0.5, linetype = 3) +
  coord_cartesian(xlim = c(0, 1), ylim=c(1,8), clip = "off") +
  labs(x = "", y = "", color = "", caption= "Kilde: American National Election Studies, 2020", title = "Hvor vigtigt er emnet klimaforandringer for dig?") +
  theme_minimal() +
  theme(legend.position = "top") + 
  geom_vline(xintercept = mean(forGG_ANES$concern, na.rm = T), linetype="dashed") +
  annotate(geom = "text", x = mean(forGG_ANES$concern, na.rm =T)-0.05, y = 7, label = " Gennemsnit", angle = 90, size = 3) + 
 # theme(plot.margin = unit(c(1, 1, 3, 1), "lines")) +
  annotate(geom = "text", x = c(0, 1), y = -Inf, label = c("Ikke vigtigt", "Meget vigtigt"), size = 2, color = "Dark Grey") + guides(fill = "none") +
  scale_y_discrete(labels=c("1. Less than high school credential" = "Less than high school",
                            "2.  High school graduate - High school diploma or equivalent (e.g. GED)" = "High school",
                            "3. Some college but no degree" = "Some college",
                            "4. Associate degree in college - occupational/vocational" = "Associate degree, vocational",
                            "5. Associate degree in college - academic" = "Associate degree, academic",
                            "6. Bachelor's degree (e.g. BA, AB, BS)" = "Bachelor's degree",
                            "7. Master's degree (e.g. MA, MS, MEng, MEd, MSW, MBA)" = "Master's degree",
                            "8. Professional school degree (e.g. MD, DDS, DVM, LLB, JD)/Doctoral degree (e.g." = "Professional/doctoral degree",
                            limits=c("1", "2", "3"), breaks = NULL, drop = F)) + theme(panel.grid.minor.y=element_blank(),
           panel.grid.major.y=element_blank(),
           plot.title.position = "plot")

tikz(file = "theoryedu.tex",
     standAlone=F,
     width = 9,
     height = 3,
     sanitize =T,
     )

print(plot_grid(ggeduDK, ggeduUSA, 
          ncol =2))

dev.off()

```

```{r anes age}

forGG_ANES$age_grcut <- cut(anes_timeseries_2020_stata_20220210$V201507x, 
                       breaks = c(-Inf, 29, 39, 49, 59, 69, Inf), 
                       labels = c("18-29 år", "30-39 år", "40-49 år", "50-59 år","60-69 år", "70+ år"), 
                       right = FALSE)

Gage <- forGG_ANES %>%
  group_by(age_grcut) %>%
  summarize(AvgConcern = mean(concern, na.rm = T),
            SDConcern = sd(concern, na.rm = T))

age_tally <- forGG_ANES %>% count(age_grcut)
AgeTally <- age_tally$n
Gage <- cbind(Gage,AgeTally)

#Laver nogle intervaller
Gage$low <- Gage$AvgConcern - (1.96 * (Gage$SDConcern/(sqrt(Gage$AgeTally))))
Gage$high <- Gage$AvgConcern + (1.96 * (Gage$SDConcern/(sqrt(Gage$AgeTally))))

ggageUS <- ggplot(Gage, aes(x = AvgConcern, y = age_grcut)) + geom_point() +
geom_errorbar(aes(xmin=low, xmax = high), alpha=0.5, linetype = 3) +
  coord_cartesian(xlim = c(0, 1), ylim=c(1,6), clip = "off") +
  labs(x = "", y = "", color = "", title = "Hvor vigtigt er emnet klimaforandringer for dig?", caption = "Kilde: American National Election Studies, 2020") +
  theme_minimal() +
  theme(legend.position = "top") + 
  geom_vline(xintercept = mean(forGG_ANES$concern, na.rm = T), linetype="dashed") +
  annotate(geom = "text", x = mean(forGG_ANES$concern, na.rm =T)-0.05, y = 1.5, label = " Gennemsnit", angle = 90, size = 3) + 
 # theme(plot.margin = unit(c(1, 1, 3, 1), "lines")) +
  annotate(geom = "text", x = c(0, 1), y = -Inf, label = c("Ikke vigtigt", "Meget vigtigt"), size = 2, color = "Dark Grey") + guides(fill = "none") +
  scale_y_discrete(labels=c("1" = "Republican", "2" = "Democrat", "Uafhængig", limits=c("1", "2", "3"), breaks = NULL, drop = F)) + theme(panel.grid.minor.y=element_blank(),
           panel.grid.major.y = element_blank())

tikz(file = "theoryage.tex",
     standAlone=F,
     width = 9,
     height = 3,
     sanitize =T,
     )

print(plot_grid(ggageDK, ggageUS, 
          ncol =2))

dev.off()

```




```{r}
#Importér data

Valg2019 <- read_dta("Valg2019.dta")
```


```{r}
#Omkod
Valg2019$q60_1_resp[Valg2019$q60_1_resp == 6] = NA
```

```{r}

Valg2019$parti <- to_factor(Valg2019$q120)

Valg2019$q60_1_resp <- range01(Valg2019$q60_1_resp, na.rm = T)
Valg2019$q60_1_resp <- Valg2019$q60_1_resp*(-1)+1


```

```{r}
G1 <- Valg2019 %>%
  group_by(parti) %>%
  summarize(AvgClimate = mean(q60_1_resp, na.rm = T),
            SDClimate = sd(q60_1_resp, na.rm = T)) %>% 
  mutate(parti = fct_reorder(parti, AvgClimate))

parti_tally <- Valg2019 %>% count(parti)

ptally <- parti_tally$n

G1_2<- cbind(G1,ptally)


#Smid irrelevante
G1_2 <- G1_2[-c(14:19), ]

#Lav nogle ints:
G1_2$low <- G1_2$AvgClimate - (1.96 * (G1_2$SDClimate/(sqrt(G1_2$ptally))))
G1_2$high <- G1_2$AvgClimate + (1.96 * (G1_2$SDClimate/(sqrt(G1_2$ptally))))


ggpartyDR <- ggplot(G1_2, aes(x = AvgClimate, y = parti, size=ptally)) +  
  geom_linerange(aes(xmin = low, xmax = high), linetype = 3, size = 0.5, alpha = 0.5) + 
  geom_rect(aes(xmin=mean(Valg2019$q60_1_resp, na.rm =T),xmax=Inf,ymin=-Inf,ymax=Inf,fill="#377EB8"), alpha=0.02) +
  geom_rect(aes(xmin=-Inf,xmax=mean(Valg2019$q60_1_resp, na.rm =T),ymin=-Inf,ymax=Inf,fill="#E41A1C"), alpha=0.02)+
  geom_point(alpha=0.3) +
  coord_cartesian(xlim = c(0, 1), clip = "off") +
  labs(x = "", y = "", color = "", title = "", size = "Antal stemmetilkendegivelser") +
  theme_minimal() +
  theme(legend.position = "bottom") + 
  geom_vline(xintercept = mean(Valg2019$q60_1_resp, na.rm = T), linetype="solid") +
  annotate(geom = "text", x = mean(Valg2019$q60_1_resp, na.rm =T)-0.02, y = 11, label = " Gennemsnit", angle = 90, size = 3) + 
 # theme(plot.margin = unit(c(1, 1, 3, 1), "lines")) +
  annotate(geom = "text", x = c(1, 0), y = -Inf, label = c("Helt enig", "Helt uenig"), size = 2, color = "Dark Grey") + guides(fill = "none")
```

```{r}
G2 <- ggplot(Valg2019 %>% drop_na(q60_1_resp), aes(alder,as.factor(q60_1_resp)))
G2 + geom_boxplot()

```

```{r}
GHoldning <- Valg2019 %>%
  group_by(alderkat) %>%
  summarize(AvgClimate = mean(q60_1_resp, na.rm = T),
            SDClimate = sd(q60_1_resp, na.rm = T))

GHoldning$alderkat <- GHoldning$alderkat %>% to_factor()

alder_tally <- Valg2019 %>% count(alderkat)
AgeTally <- alder_tally$n
GHoldning<- cbind(GHoldning,AgeTally)

#Lav nogle ints
GHoldning$low <- GHoldning$AvgClimate - (1.96 * (GHoldning$SDClimate/(sqrt(GHoldning$AgeTally))))
GHoldning$high <- GHoldning$AvgClimate + (1.96 * (GHoldning$SDClimate/(sqrt(GHoldning$AgeTally))))

ggageDK <- ggplot(GHoldning, aes(x = AvgClimate, y = alderkat)) + geom_point() + 
  geom_errorbar(aes(xmin= low, xmax = high),linetype = 3) +
  coord_cartesian(xlim = c(0, 1), clip = "off") +
  labs(x = "", y = "", color = "", title = "Er klimaet den vigtigste udfordring i vores levetid?", size = "Antal stemmetilkendegivelser", caption = "Kilde: Valgundersøgelsen 2019") +
  theme_minimal() +
  theme(legend.position = "top") + 
  geom_vline(xintercept = mean(Valg2019$q60_1_resp, na.rm = T), linetype="dashed") +
  annotate(geom = "text", x = mean(Valg2019$q60_1_resp, na.rm =T)-0.05, y = 1.5, label = " Gennemsnit", angle = 90, size = 3) + 
 # theme(plot.margin = unit(c(1, 1, 3, 1), "lines")) +
  annotate(geom = "text", x = c(1, 0), y = -Inf, label = c("Helt enig", "Helt uenig"), size = 2, color = "Dark Grey") + guides(fill = "none") + theme(panel.grid.minor.y=element_blank(),
           panel.grid.major.y = element_blank())
```

```{r}
#Uddannelse

Valg2019$udd <- Valg2019$udd %>% to_factor()

GEduc <- Valg2019 %>%
  group_by(udd) %>%
  summarize(AvgClimate = mean(q60_1_resp, na.rm = T),
            SDClimate = sd(q60_1_resp, na.rm = T))

edu_tally <- Valg2019 %>% count(udd)
EduTally <- edu_tally$n
GEduc<- cbind(GEduc,EduTally)

GEduc_2 <- GEduc[-7, ]

#Laver nogle intervaller
GEduc_2$low <- GEduc_2$AvgClimate - (1.96 * (GEduc_2$SDClimate/(sqrt(GEduc_2$EduTally))))
GEduc_2$high <- GEduc_2$AvgClimate + (1.96 * (GEduc_2$SDClimate/(sqrt(GEduc_2$EduTally))))


ggeduDK <- ggplot(GEduc_2, aes(x = AvgClimate, y = udd)) + geom_point() +
geom_errorbar(aes(xmin=low, xmax = high), alpha=0.5, linetype = 3) +
  coord_cartesian(xlim = c(0, 1), clip = "off") +
  labs(x = "", y = "", color = "", title = "Er klimaet den vigtigste udfordring i vores levetid?", size = "Antal stemmetilkendegivelser", caption = "Kilde: Valgundersøgelsen 2019") +
  theme_minimal() +
  theme(legend.position = "top") + 
  geom_vline(xintercept = mean(Valg2019$q60_1_resp, na.rm = T), linetype="solid") +
  annotate(geom = "text", x = mean(Valg2019$q60_1_resp, na.rm =T)-0.05, y = 5.5, label = " Gennemsnit", angle = 90, size = 3) + 
 # theme(plot.margin = unit(c(1, 1, 3, 1), "lines")) +
  annotate(geom = "text", x = c(1, 0), y = -Inf, label = c("Helt enig", "Helt uenig"), size = 2, color = "Dark Grey") + guides(fill = "none") + theme(panel.grid.minor.y=element_blank(),
           panel.grid.major.y = element_blank(),
            plot.title.position = "plot")

```

```{r}

#Tikz-kode
library(tikzDevice)
tikz('figs/simpleEx.tex',width=3.5,height=3.5)
plot(1,main='Hello World!')
dev.off()
```

```{r}
Valg2019$koen <- Valg2019$koen %>% to_factor()

Gkoen <- Valg2019 %>%
  group_by(koen) %>%
  summarize(AvgClimate = mean(q60_1_resp, na.rm = T),
            SDClimate = sd(q60_1_resp, na.rm = T))

koen_tally <- Valg2019 %>% count(koen)
KoenTally <- koen_tally$n
Gkoen<- cbind(Gkoen,KoenTally)

#Laver nogle intervaller
Gkoen$low <- Gkoen$AvgClimate - (1.96 * (Gkoen$SDClimate/(sqrt(Gkoen$KoenTally))))
Gkoen$high <- Gkoen$AvgClimate + (1.96 * (Gkoen$SDClimate/(sqrt(Gkoen$KoenTally))))

ggmaleDR <- ggplot(Gkoen, aes(x = AvgClimate, y = fct_rev(as_factor(koen)))) + geom_point() +
geom_errorbar(aes(xmin=low, xmax = high), alpha=0.5, linetype = 3, size=0.5) +
  coord_cartesian(xlim = c(0, 1), clip = "off") +
  labs(x = "", y = "", color = "", title = "Er klimaet den vigtigste udfordring i vores levetid?\n ", caption = "Kilde: Valgundersøgelsen 2019") +
  theme_minimal() +
  theme(legend.position = "top") + 
  geom_vline(xintercept = mean(Valg2019$q60_1_resp, na.rm = T), linetype="dashed") +
  annotate(geom = "text", x = mean(Valg2019$q60_1_resp, na.rm =T)-0.02, y = .8, label = " Gennemsnit", angle = 90, size = 3) + 
 # theme(plot.margin = unit(c(1, 1, 3, 1), "lines")) +
  annotate(geom = "text", x = c(1, 0), y = -Inf, label = c("Helt enig", "Helt uenig"), size = 2, color = "Dark Grey") + guides(fill = "none") + theme(panel.grid.minor.y=element_blank(),
           panel.grid.major.y=element_blank())
```

